package com.app.account.impl;


import com.app.account.dao.AccountMapper;
import com.app.common.entity.Account;
import com.app.common.service.AccountService;
import com.xhga.transaction.common.annotation.XHGATransaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xhga
 * @since 2019-04-03
 */
@Service("accountService")
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountMapper accountMapper;

    @Override
    public Account getAccount(int id) {
        return accountMapper.selectByPrimaryKey(id);
    }

    @XHGATransaction(type = "test", names = {"account","order"}, name = "account", serverCount = 2)
    @Override
    public int updateMoney(int id, double money) throws Exception {
        int flag = accountMapper.reduceMoney(id, money);
        System.out.println("修改余额状态:" + flag);
        if (flag <= 0) {
            throw new Exception();
        }
        return flag;
    }

}
